package com.example.jhq.nfcreader;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.jhq.nfcreader.NFC.NFCActivity;
import com.example.jhq.nfcreader.QRCODE.QRCodeActivity;
import com.tbruyelle.rxpermissions2.RxPermissions;

public class MainActivity extends Activity implements View.OnClickListener{

    public Button btn_nfc;

    public Button btn_qrcode;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn_nfc = findViewById(R.id.btn_nfc);
        btn_qrcode = findViewById(R.id.btn_qrcode);

        btn_nfc.setOnClickListener(this);
        btn_qrcode.setOnClickListener(this);


        RxPermissions rxPermissions = new RxPermissions(this);

        rxPermissions
                .request(Manifest.permission.CAMERA)
                .subscribe(granted -> {
                    if (granted) { // Always true pre-M
                        // I can control the camera now

                    } else {
                        // Oups permission denied
                        Toast.makeText(MainActivity.this,"请去设置中将照相机权限打开!",Toast.LENGTH_SHORT).show();
                    }
                });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){

            case R.id.btn_nfc:
                startActivity(new Intent(MainActivity.this, NFCActivity.class));
                break;

            case R.id.btn_qrcode:
                startActivity(new Intent(MainActivity.this, QRCodeActivity.class));
                break;
        }
    }
}
